//
//  BKHomeViewController.m
//  OtherDemo
//
//  Created by lianjie on 2018/7/23.
//  Copyright © 2018年 lianjie. All rights reserved.
//

#import "DEWBKHomeViewController.h"
#import "UIBarButtonItem+MainBar.h"
#import "CHCycleScrollView.h"
#import "DEWBKHomeCell.h"
#import "DEWBKInforViewController.h"
//#import "DELoginModel.h"
#import "HHUserManager.h"

static NSString *const cellID = @"bkhome";
@interface DEWBKHomeViewController ()<UITableViewDelegate,UITableViewDataSource>
/** <#type#> */
@property (strong, nonatomic) UITableView *tableView;

@end

@implementation DEWBKHomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self loadData];
    
    [self createView];
}

#pragma mark ----RequestData
-(void)loadData
{
    NSString *url = [KSService queryBKList];
    DELoginModel *model = [HHUserManager getUserInfo];
    NSDictionary *dic = @{
                          @"userId":model.userId,
                          @"tokenId":model.tokenId,
                          @"estateId":@"",//小区的Id
                          @"page":@(1)
                          };
    __weak typeof(self)weakSelf = self;
    [KSHTTPSTool post:url params:dic success:^(id responseObject) {
//        if (DERetCode) {
//            NSArray *arr = responseObject[@"data"];
//        }else{
//            [[AlertHelper sharedManager]alertWithMessage:[NSString stringWithFormat:@"%@",responseObject[@"retMsg"]]];
//        }
    } failure:^(NSError *error) {
        [weakSelf showHint:@"系统异常，稍后再试！"];
    }];
    
}


#pragma mark ----initView
-(void)createView
{
    self.navigationItem.title = @"邻里百科";
    UIBarButtonItem *rightItem = [UIBarButtonItem itemWithTarget:self action:@selector(rightBarButtonItemClick) image:@"更多" highImage:@"更多搜索" andTitle:nil];
    self.navigationItem.rightBarButtonItem = rightItem;
    
    [self creatTab];
    
    
}
#pragma mark - 导航栏按钮点击事件
-(void)rightBarButtonItemClick{
    
    
    
}

-(void)creatTab{
    _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, DEWScreenWidth , DEWScreenHeight - NAVH) style:UITableViewStyleGrouped];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:_tableView];
    if (@available(iOS 11.0, *)){
        _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        self.tableView.estimatedRowHeight = 0;
        self.tableView.estimatedSectionHeaderHeight = 0;
        self.tableView.estimatedSectionFooterHeight = 0;
    }

    [self.tableView registerNib:[UINib nibWithNibName:NSStringFromClass([DEWBKHomeCell class]) bundle:nil] forCellReuseIdentifier:cellID];
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 20;
    
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    if (indexPath.row == 0) {
        NSString *cellID = [NSString stringWithFormat:@"12%ld%ld",(long)indexPath.section,(long)indexPath.row];
        UITableViewCell *cell = nil;
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        NSArray *arr = @[@"",@"",@""];
        CHCycleScrollView *scrollView = [[CHCycleScrollView alloc]initWithFrame:CGRectMake(0, 0, DEWScreenWidth, 170) imageGroups:arr];
        
        [cell addSubview:scrollView];
        return cell;
    }else{
        DEWBKHomeCell *HomeCell = [tableView dequeueReusableCellWithIdentifier:cellID];
        
        return HomeCell;
    }
    
    
    
    return nil;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
        return 170;
    }else{
        return 180;
    }
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0.001;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.001;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    
    if (indexPath.row > 0 ) {
        DEWBKInforViewController *info  = [[DEWBKInforViewController alloc]init];
        
        [self.navigationController pushViewController:info animated:YES];
    }
}


#pragma mark ---lazy

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
